package deng.ejb3.examples.simplecase.client;

import javax.naming.Context;
import javax.naming.InitialContext;

import deng.ejb3.examples.simplecase.Constants;
import deng.ejb3.examples.simplecase.EmployeeWorkSessionRemote;
import deng.ejb3.examples.simplecase.SessionBreak;

public class EmployeeWorkSessionClient {
	
	public static void main(String[] args) {
		
		// Let's create some employee first
		SendCreateNewEmployeeToQueue.main(args);
		
		// Let's do a work session test
		Context ctx = null;		
		try {
			ctx = new InitialContext();
			EmployeeWorkSessionRemote ews = (EmployeeWorkSessionRemote)ctx.lookup(Constants.EMPLOYEE_WORK_SESSION_BEAN_REMOTE);

			
			System.out.println("Starting to test Work session.");
			Long employeeId = 1L;
			ews.beginWorkSession(employeeId);

			MainHelper.sleep(1000);
			ews.takeBreak(SessionBreak.BreakType.SMALL);
			
			MainHelper.sleep(1000);
			ews.resumeBreak();
			
			MainHelper.sleep(1000);
			ews.endWorkSession();
			
			System.out.println("Work session test completed.");
			
		} catch (Exception e) {
			throw new RuntimeException("Failed to create employee work session.", e);
		} finally {
			MainHelper.close(ctx);
		}
	}
	
	
}
